package com.hanhanxiaochong.zhongxiangchuanmei.view.order.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.ExpressBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ItemViewDelegate;
import com.hanhanxiaochong.zhongxiangchuanmei.config.MultiItemTypeAdapter;
import com.hanhanxiaochong.zhongxiangchuanmei.config.ViewHolder;

import java.util.List;

/**
 * Created by RockPhoenix on 2018/6/24.
 */

public class LogisticsAdapter extends MultiItemTypeAdapter<ExpressBean.DataBean> {


    public LogisticsAdapter(Context context, List<ExpressBean.DataBean> datas) {
        super(context, datas);

        addItemViewDelegate(new LogisticsAdapter.ReceivingAddressDelegate());
        addItemViewDelegate(new LogisticsAdapter.ItemLogisticDelegate());
    }

    class ReceivingAddressDelegate implements ItemViewDelegate<ExpressBean.DataBean> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.header_logistics;
        }

        @Override
        public boolean isForViewType(ExpressBean.DataBean item, int position) {
            return item.getTime() == null;
        }

        @Override
        public void convert(ViewHolder holder, ExpressBean.DataBean bean, int position) {
            TextView process = holder.getView(R.id.item_logistic_process);
            process.setTextColor(mContext.getResources().getColor(R.color.light_gray));

        }
    }

    class ItemLogisticDelegate implements ItemViewDelegate<ExpressBean.DataBean> {

        @Override
        public int getItemViewLayoutId() {
            return R.layout.item_logistic;
        }

        @Override
        public boolean isForViewType(ExpressBean.DataBean item, int position) {
            return item.getTime() != null;
        }

        @SuppressLint("SetTextI18n")
        @Override
        public void convert(ViewHolder holder, ExpressBean.DataBean bean, int position) {
            TextView time = holder.getView(R.id.tv_logistic_time);
            TextView date = holder.getView(R.id.tv_logistic_date);
            TextView process = holder.getView(R.id.item_logistic_process);
            if (position == 1) {
                time.setTextColor(mContext.getResources().getColor(R.color.black));
                date.setTextColor(mContext.getResources().getColor(R.color.black));
                process.setTextColor(mContext.getResources().getColor(R.color.black));
            } else {
                time.setTextColor(mContext.getResources().getColor(R.color.light_gray));
                date.setTextColor(mContext.getResources().getColor(R.color.light_gray));
                process.setTextColor(mContext.getResources().getColor(R.color.light_gray));
            }
            String[] split = bean.getTime().split(" ");
            time.setText(split[1]);
            String[] split1 = split[0].split("-");
            date.setText(split1[1] + "-" + split1[2]);
            process.setText(bean.getContext());
        }
    }
}
